import processing.core.PApplet;


/**
 * @author Matt Sponnar
 *
 */
public class GSquare {
	
	int width, height, originx, originy, posx, posy;
	PApplet parent;
	Snowflake mine;
	
	
	public GSquare(int posx, int posy, int w, int h, PApplet p){		
		width = w;
		height = h;
		this.posx = posx;
		this.posy = posy;
		originx = width/2;
		originy = height/2;
		parent = p;
		mine = new Snowflake(p, originx, originy, width, height);
	}
	
	public void setup(){
		
		parent.stroke(255);
	}
	
	public void display(boolean prediction, int max){
		
		parent.fill(255);
		parent.line(posx, posy, posx + width, posy); //top
		parent.line(posx, posy + height, posx + width, posy + height); //bot
		parent.line(posx, posy, posx, posy + height); //left
		parent.line(posx + width, posy, posx + width, posy + height); //right
		
		int color[] = new int[3];
		if(prediction == true){
			color[0] = 255;
			color[1] = 0;
			color[2] = 0;
		}
		else{
			color[0] = 255;
			color[1] = 255;
			color[2] = 255;
		}
		mine.setup(color, max);
		mine.display();
	}
	
	
	/*
	 * For each mutation 
	 * 	Draw a rectangle and fill with that color
	 * 	Increment the position for the next mutation
	 */
	public void displayMutations(int[] mutations){
		
		int x = 5, y = 5, w = 10;
		
		for(int i = 0; i < mutations.length; i++){
			
			if(mutations[i] == 1){
				int[] color = this.setColor(i);
				parent.stroke(255);
				parent.fill(color[0], color[1], color[2]);
				parent.rect(x, y, w, w);
				x += 10;
			}
		}
	}
	
	public int[] setColor(int i) {
		
		int c1[] = new int[]{255, 255, 255};
		
		switch(i){
		case 0:
			c1 = new int[]{255, 140, 0}; //orange a388
			break;
		case 1:
			c1 = new int[]{199, 21, 133};//pink a389
			break;
		case 2:
			c1 = new int[]{0, 255, 0};//green a391
			break;
		case 3:
			c1 = new int[]{0, 0, 255};//blue a392
			break;
		case 4:
			c1  = new int[]{255, 255, 0};//yellow a394
			break;
		case 5:
			c1  = new int[]{139, 115, 85};//brown a395
			break;
		}
		
		return c1;
	}

	/*
	 * Getters and Setters
	 */
	public int getWidth() {
		return width;
	}

	public Snowflake getMine() {
		return mine;
	}

	public void setMine(Snowflake mine) {
		this.mine = mine;
	}


	public void setWidth(int width) {
		this.width = width;
	}


	public int getHeight() {
		return height;
	}


	public void setHeight(int height) {
		this.height = height;
	}


	public int getOriginx() {
		return originx;
	}


	public void setOriginx(int originx) {
		this.originx = originx;
	}


	public int getOriginy() {
		return originy;
	}


	public void setOriginy(int originy) {
		this.originy = originy;
	}
	
}
